#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 1e6 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//

int n, k;
int a[N];
int main()
{
    close();
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cin >> k;

    multiset<int> st;
    queue<int> q;
    int mi = 0x3f3f3f3f;
    if(n <= 2 * k + 1)
    {
        for(int i = 1; i <= n; i++)mi = min(a[i], mi);
        for(int i = 1; i <= n; i++) cout << mi << " ";
        cout << '\n';
        return 0;
    }

    vector<int> v1;
    for(int i = 1; i <= n; i++)
    {
        if(q.size() < 2 * k + 1)
        {
            q.push(a[i]);
            st.insert(a[i]);
            if(q.size() == 2 * k + 1)
            {
                v1.push_back(*st.begin());
            }
        }
        else
        {
            v1.push_back(*st.begin());
            int t = q.front();
            q.pop();
            q.push(a[i]);
            st.erase(t);
            st.insert(a[i]);
        }

    }
    int m = n - v1.size();
    while(m--) v1.push_back(*st.begin());

    for(auto &k : v1) cout << k << " ";
    cout << '\n';



    return 0;
}